package com.tanguy.driver.ui.window

import android.content.Context
import android.view.View
import android.widget.TextView
import com.tanguy.driver.R
import com.tanguy.driver.base.BasePopupWindow

import com.tanguy.user.utlis.extend.click
import com.tanguy.user.utlis.extend.setText
import org.jetbrains.anko.find

/**
 * Created by dab on 2017/11/15 0015 14:14
 */
class MessageWindow(context: Context, private var msg: String, var haveLift: Boolean = true, private val sureClick: (right: Boolean) -> Unit) : BasePopupWindow(context) {

    constructor(context: Context, msg: String, sureClick: (right: Boolean) -> Unit) : this(context, msg, true, sureClick)

    override fun setContentRes(): Int = R.layout.window_message
    lateinit var content: TextView
    lateinit var cancel: View
    lateinit var line: View
    override fun initView(view: View) {
        super.initView(view)
        view.apply {
            content = find(R.id.tv_content)
            cancel = find(R.id.tv_cancel)
            line = find(R.id.view_line)
            click(cancel) {
                sureClick.invoke(false)
                dismiss()
            }
            click(R.id.tv_confirm) {
                sureClick.invoke(true)
                dismiss()
            }

        }
    }

    fun setBtnText(left: String, right: String): MessageWindow {
        contentView.setText(R.id.tv_cancel, left)
        contentView.setText(R.id.tv_confirm, right)
        return this
    }

    override fun initEvent() {
        super.initEvent()
        content.text = msg
        if (!haveLift) {
            cancel.visibility = View.GONE
            line.visibility = View.GONE
        }
    }
}